package cn.Y_Qiu.basic.service.impl;

import cn.Y_Qiu.basic.mapper.BaseMapper;
import cn.Y_Qiu.basic.query.BaseQuery;
import cn.Y_Qiu.basic.service.IBaseService;
import cn.Y_Qiu.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> mapper;

    @Override
    @Transactional
    public void add(T t) {
        mapper.add(t);
    }

    @Override
    @Transactional
    public void remove(Long id) {
        mapper.remove(id);
    }

    @Override
    @Transactional
    public void update(T t) {
        mapper.update(t);
    }

    @Override
    public List<T> listAll() {
        return mapper.listAll();
    }

    @Override
    public T queryById(Long id) {
        return mapper.queryById(id);
    }

    @Override
    public PageList<T> queryPage(BaseQuery tQuery) {
        Integer count = mapper.querySize(tQuery);
        List<T> Ts = mapper.queryPage(tQuery);
        return new PageList<>(count,Ts);
    }

    @Override
    public void patchremove(List<Long> ids) {
        mapper.patchremove(ids);
    }

}
